package cn.zxh.csdn_maven.work.flow.login.chains;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;

import cn.zxh.csdn_maven.base.pojo.Cookies;
import cn.zxh.csdn_maven.work.flow.login.AbstractFlowController;

public class DealCookieFlow extends AbstractFlowController{

	@Override
	public Map<String, Object> execute(HttpClient client,
			Map<String, Object> params) throws ClientProtocolException,
			IOException {
		Map<String, Object> result=new HashMap<String, Object>();
		Map<String, Object> cookieMap=new HashMap<String, Object>();
		/**处理cookie中访问量的cookie*/
		String hmvt = Cookies.getCookie("HMVT");
		/**HMVT=6bcd52f51e9b3dce32bec4a3997715ac|1507873191|*/
		String[] hmvts = hmvt.split("\\|");
		String Hm_lvt="Hm_lvt_"+hmvts[0];
		String Hm_lpvt="Hm_lpvt_"+hmvts[0];
		String hm_lvt_value = Cookies.getCookie(Hm_lvt);
		String hm_lpvt_value=hmvts.length>1?hmvts[1]:"zxh";
		if("undefined".equals(hm_lvt_value)){
			hm_lvt_value=hm_lpvt_value;
		}else {
			hm_lvt_value+=","+hm_lpvt_value;
		}
		cookieMap.put(Hm_lvt, hm_lvt_value);
		cookieMap.put(Hm_lpvt, hm_lpvt_value);
		Cookies.setCookies(cookieMap);
		Cookies.delCookie("HMVT");
		result.put("msg", "success");
		return result;
	}

	@Override
	public String getBaseUrl() {
		// TODO Auto-generated method stub
		return "";
	}

}
